SQL JOINS
A JOIN is used to combines rows from two or more tables, based on a related column between them. In other words JOINS are used to fetch data from two or more tables. When you want to perform a SQL statement to attached two or more table’s column then we use SQL JOINS.
Types of Joins:
• INNER JOIN (simple join)
• LEFT OUTER JOIN (LEFT JOIN)
• RIGHT OUTER JOIN (RIGHT JOIN)
• FULL OUTER JOIN (FULL JOIN)
Let’s see in Examples:
We have 2 Tables ‘Employee’ and ‘Company’:
Employee
Company
INNER JOIN (simple join):
If you want to use Inner join then you use INNER JOIN keyword or JOIN.
By using INNER JOIN only those record are fetched that are satisfy the condition in both table.
INNER JOIN Syntax
SELECT column name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
Example:
LEFT OUTER JOIN (LEFT JOIN):
When you are use LEFT JOIN OR LEFT OUTER JOIN thenit returns all records from the left table and matched record from the right table. It return NULL from the right side, if there is no match.
LEFT JOIN Syntax
SELECT column name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
Example:
RIGHT OUTER JOIN (RIGHT JOIN):
When you are use RIGHT JOIN OR RIGHT OUTER JOIN thenit returns all records from the right table and matched record from the left table. It return NULL from the left side, if there is no match.
RIGHT JOIN Syntax
SELECT column name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
Example:
FULL OUTER JOIN (FULL JOIN):
When you are use FULL JOIN OR FULL OUTER JOIN thenit returns all records from the Right and Left table with matched and Non-matched with NULL value.
FULL JOIN Syntax
SELECT column name(s) FROM table1 FULL JOIN table2 ON table1.column_name = table2.column_name;
Example:
I hope you are Understand Join Concept Thank you…
Leave Comment